<template>
	<view>
		<view class="u-m-t-30">
			{{title}}
		</view>
		<view class="u-flex">
			<view class="w-type" v-for="(item,idx) in data" :key="idx" :class="{'select':select==idx,'disabled':disabled(item.id)}" @click="selectType(idx)">
				{{item.name}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "w-detail-type",
		props: {
			title: {
				type: String,
				default: ''
			},
			index: {
				type: Number,
				default: 0
			},
			data: {
				type: Array,
				default: () => {
					return []
				}
			},
			haveSku:{
				type: Object,
				default: () => {
					return {}
				}
			}
		},
		computed:{
			disabled(){
				return function(id){
					return `s${this.index+1}`!=this.haveSku.name && !this.haveSku.list.includes(id)
				}
			}
		},
		data() {
			return {
				select:null
			};
		},
		mounted() {
			this.selectType(0)
		},
		methods: {
			selectType(index) {
				if(this.select == index) return
				this.select = index
				this.$emit('selectType',this.data[index],this.index)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.disabled {
	    pointer-events: none;
	    cursor: default;
	    opacity: 0.6;
	}
	.w-type {
		border: 1px solid #ff9900;
		border-radius: 8rpx;
		padding: 10rpx 20rpx;
		background-color: #fdf6ec;
		color: #ff9900;
		margin-top: 20rpx;
		font-size: 22rpx;
	}
	.select{
		color: #FFFFFF;
		background-color: #ff9900;
	}
	.w-type+.w-type {
		margin-left: 20rpx;
	}
</style>
